
import java.util.ArrayList;
import java.util.GregorianCalendar;
import jpa.JPAConnection;
import jpa.entities.Employee;
import jpa.entities.Item;
import jpa.entities.ItemType;
import jpa.entities.Project;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Remco Haszing
 * @author Jorik Heijstek
 */
public class ResetDatabase {

    JPAConnection jpa;
    String pass = "trololol";

    @Before
    public void setUp() {
        jpa = new JPAConnection("BaalzebubPU");
    }

//    @Test
//    public void fillDatabase() {
//        createUsers();
//        editUser();
//        createProjects();
//        createItems();
//    }

    @Test
    public void createUsers() {
        ArrayList<Employee> users = new ArrayList<Employee>();
        String[] phone = {"6660013370666"};
        String[] email = {"email@gmail.com"};
        String[] website = {"website.com"};
        users.add(new Employee("trollhammaren", "Haszing", "Remco", "A A", new GregorianCalendar(), new GregorianCalendar(), new GregorianCalendar(), "Somewhere", "1337XD", "Netherlands", 1234, phone, email, website, pass, true));
        users.add(new Employee("aymeric", "Blok", "Aymeric", "", new GregorianCalendar(), new GregorianCalendar(), new GregorianCalendar(), "Somewhere", "1337XD", "Netherlands", 1234, phone, email, website, pass, false));
        users.add(new Employee("vertering", "Heijstek", "Jorik", "", new GregorianCalendar(), new GregorianCalendar(), new GregorianCalendar(), "Somewhere", "1337XD", "Netherlands", 1234, phone, email, website, pass, false));
        users.add(new Employee("robin", "Fokker", "Robin", "", new GregorianCalendar(), new GregorianCalendar(), new GregorianCalendar(), "Somewhere", "1337XD", "Netherlands", 1234, phone, email, website, pass, false));
        assertEquals(4, users.size());
        for (Employee e : users) {
            if (jpa.getUserByUsername(e.getUserName(), pass) == null) {
                jpa.create(e);
            }
            assertEquals(e, jpa.getUserByUsername(e.getUserName(), pass));
        }
    }

    @Test
    public void editUser() {
        Employee e = jpa.getUserByUsername("trollhammaren", pass);
        assertNotNull(e);
        e.setTown("Somewhere Else");
        jpa.edit(e);
        assertSame(e, jpa.getUserByUsername("trollhammaren", pass));
        assertEquals("Somewhere Else", e.getTown());
    }

    @Test
    public void createProjects() {
        ArrayList<Employee> users = new ArrayList<Employee>();
        Employee t = jpa.getUserByUsername("trollhammaren", pass);
        Employee a = jpa.getUserByUsername("aymeric", pass);
        Employee v = jpa.getUserByUsername("vertering", pass);
        Employee r = jpa.getUserByUsername("robin", pass);
        users.add(t);
        users.add(a);
        users.add(v);
        users.add(r);
        Project p = new Project("Baalzebub", t, new GregorianCalendar(), new GregorianCalendar(), users);
        jpa.create(p);
        users = new ArrayList<Employee>();
        users.add(t);
        users.add(a);
        users.add(v);
        p = new Project("Air Traffic Control", v, new GregorianCalendar(), new GregorianCalendar(), users);
        jpa.create(p);
        users = new ArrayList<Employee>();
        users.add(t);
        users.add(a);
        p = new Project("Star Sweeper", a, new GregorianCalendar(), new GregorianCalendar(), users);
        jpa.create(p);
        jpa.edit(t);
        jpa.edit(a);
        jpa.edit(v);
        jpa.edit(r);
    }

    @Test
    public void createItems() {
        Employee e = jpa.getUserByUsername("trollhammaren", pass);
        Project[] projects = e.getProjects();
        for (Project p : projects) {
            Item r = p.getRootFolder();
            Item f1 = new Item(ItemType.FOLDER, "Storyline", "This folder contains the storyline items", "Chapters, paragraphs and quotes can be found here.", null, e);
            r.add(f1);
            jpa.create(f1);
            Item sf1 = new Item(ItemType.FOLDER, "Chapters", "This folder contains the finished chapters", "Only finished chapters are to be placed into this folder.", null, e);
            f1.add(sf1);
            jpa.create(sf1);
            Item i1 = new Item(ItemType.CHAPTER, "Prologue", "The prologue of the game", "Final version: No more changes to be made", null, e);
            sf1.add(i1);
            jpa.create(i1);
            Item i2 = new Item(ItemType.PARAGRAPH, "Paragraph 1 chapter 3", "A part of chapter 3", "Ideas for before and after this part", null, e);
            f1.add(i2);
            jpa.create(i2);
            
            Item f2 = new Item(ItemType.FOLDER, "Visual art", "This folder contains the visual art", "Sketches, characters, photos and drawings can be found here.", null, e);
            r.add(f2);
            jpa.create(f2);
            Item sf2 = new Item(ItemType.FOLDER, "Sketches", "This folder contains all of the sketches", "Sketches of background, characters, buildings, etc. can be found here.", null, e);
            f2.add(sf2);
            jpa.create(sf2);
            Item ssf1 = new Item(ItemType.FOLDER, "Backgrounds", "This folder contains all of the background sketches", "Only sketches of backgrounds, thus no finished products, should be placed in this folder.", null, e);
            sf2.add(ssf1);
            jpa.create(ssf1);
            Item ssf2 = new Item(ItemType.FOLDER, "Guns", "This folder contains all of the gun sketches", "Only sketches of guns, thus no finished products, should be placed in this folder.", null, e);
            sf2.add(ssf2);
            jpa.create(ssf2);
            Item i3 = new Item(ItemType.CHARACTER, "Character Boy 1", "Random boy villager", "Final version: No more changes to be made", null, e);
            f2.add(i3);
            jpa.create(i3);
            Item i4 = new Item(ItemType.DRAWING, "Drawing Background 2", "Near completion", "Needs more details", null, e);
            f2.add(i4);
            jpa.create(i4);
            Item i5 = new Item(ItemType.PHOTO, "Photo Building inspiration 1", "Short description", "A very very long description", null, e);
            f2.add(i5);
            jpa.create(i5);
            Item i6 = new Item(ItemType.SKETCH, "Sketch Gun 5", "Short description", "A very very long description", null, e);
            ssf2.add(i6);
            jpa.create(i6);

            Item f3 = new Item(ItemType.FOLDER, "Audio", "This folder contains the audio", "Music, voices, background sounds and foley sounds can be found here.", null, e);
            r.add(f3);
            jpa.create(f3);
            Item i7 = new Item(ItemType.MUSIC, "Backgroundmusic Battle", "The main battlemusic", "Final version: No more changes to be made", null, e);
            f3.add(i7);
            jpa.create(i7);
            
            Item f4 = new Item(ItemType.FOLDER, "Code", "This folder contains the code", "Programs and code excerpts can be found here.", null, e);
            r.add(f4);
            jpa.create(f4);
            Item i8 = new Item(ItemType.PROGRAM, "Movement program", "The main handler for movement of the player", "Still needs link to player, powerups and negative effects", null, e);
            f4.add(i8);
            jpa.create(i8);
        }
    }
}